package com.fengxing.ams.web.facade.mouble.user;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface IMenuDao extends PagingAndSortingRepository<MenuVO, Long>, JpaSpecificationExecutor<MenuVO> {
	
	@Query("select distinct m from MenuVO m, RoleVO r, UserVO u where m in elements (r.menuList) and r in elements (u.roleList)" +
		   " and u.userId=:userId order by m.sort")
	public List<MenuVO> findByUserId(@Param("userId") Long userId);

	@Query(value = "SELECT b.* FROM zyt_sys_role_menu a, zyt_sys_menu b WHERE a.`menu_id`=b.`menu_Id` AND a.`role_id` IN (:roleIdList) ORDER BY b.`sort`", nativeQuery=true)
	public List<MenuVO> findMenuByRoleIdList(@Param("roleIdList")List<Long> roleIdList);
}
